﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TianYi
{
    public class PcToPlc
    {
        PlcController _plc;
        public PcToPlc(PlcController plcInstance)
        {
            _plc = plcInstance;
        }
        //plc心跳信号
        private short _watchDog10;

        //允许加工信号
        private int _allowOP10Left;
        private int _allowOP10Right;
        private int _allowOP20;
        private int _allowOP30;
        #region 心跳信号
        /// <summary>
        /// 心跳plcop10左工位
        /// </summary>
        public short WatchDog10
        {
            get
            {
                return _watchDog10;
            }
            set
            {
                _watchDog10 = value;
                _plc.WriteInt("DB1000.DBW0", _watchDog10);
            }
        }

        #endregion


        #region 反馈完成信号
        /// <summary>
        /// 总请求反馈完成信号
        /// </summary>
        public void UploadDoneSign(short sign)
        {

            _plc.WriteInt("DB1000.DBW4", sign);

        }

        /// <summary>
        /// 完成信号工站1
        /// </summary>
        public void UploadDoneSignStation1(short sign)
        {

            _plc.WriteInt("DB1000.DBW8", sign);

        }
        /// <summary>
        /// 完成信号工站2
        /// </summary>
        public void UploadDoneSignStation2(short sign)
        {
            _plc.WriteInt("DB1000.DBW12", sign);
        }
        #endregion


        #region 允许加工
        /// <summary>
        /// 允许op10左工位工作
        /// </summary>
        public int AllowOP10Left
        {
            get
            {
                return _allowOP10Left;
            }
            set
            {
                _allowOP10Left = value;
                _plc.WriteInt("DB1000.DBW8", (short)_allowOP10Left);
            }
        }
        /// <summary>
        /// 允许op10右工位工作
        /// </summary>
        public int AllowOP10Right
        {
            get
            {
                return _allowOP10Right;
            }
            set
            {
                _allowOP10Right = value;
                _plc.WriteInt("DB1000.DBW8", (short)_allowOP10Right);
            }
        }
        /// <summary>
        /// 允许op20工位工作
        /// </summary>
        public int AllowOP20
        {
            get
            {
                return _allowOP20;
            }
            set
            {
                _allowOP20 = value;
                _plc.WriteInt("DB1000.DBW8", (short)_allowOP20);
            }
        }

        /// <summary>
        /// 允许op30工位工作
        /// </summary>
        public int AllowOP30
        {
            get
            {
                return _allowOP30;
            }
            set
            {
                _allowOP30 = value;
                _plc.WriteInt("DB1000.DBW8", (short)_allowOP30);
            }
        }
        #endregion


    }

}
